-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve Honeybadger.lambdaHandler()
to return async handler
#680
Conversation
Well done @subzero10 . I've got some thoughts, but I'm currently on holiday, so it'll have to be next week |
I agree with you that a try/catch is enough, but I wonder about context (which I think is what domains were used for). For instance, in this const hb = require('honeybadger');
module.exports.handler1 = () => {
hb.context({a: "1"});
});
module.exports.handler1 = () => {
hb.context({a: "2"});
}); can we be sure these context calls won't clash if both these functions get executed, considering the same Lambda instance might be reused? I think we should add a test for that. If so, we could (should) use AsyncLocalStorage and polyfills to fix it. |
I was worried that there would be a performance penalty with
Still, I am wondering if we could just use a dictionary and store honeybadger context using key |
The dictionary approach should work, but wouldn't that possibly lead to a memory leak? We'll keep adding to the dictionary and never remove unless there's a crash. I don't know how long Lambda instances stick around for, though...🤔 |
Good question. I wonder if there's a way to find that out. I will do some googling. Also, question that came up now: Even if the lambda instance is re-used, would it be the same nodejs process? If not, we wouldn't need to do anything here right? |
Yeah, if it's a different process,, we would be safe. But considering that the reused instance already has the state initialised, I'm leaning towards same process. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I read through the code, looking good. I added a few questions. @subzero10 are you still having issues with the setTimeout
errors? I think that may be related to why we were using domains.
Yes, I am getting this error when throwing an uncaught error in a setTimeout:
I'm still investigating. For the rest, there were times where I used to get this error:
I think it was because I was throwing the error (therefore ending the aws lambda process) before the http request to Honeybadger is completed. |
Should we implement this in this PR? I'm thinking that this potential issue already exists with the current lambdaHandler implementation, so I'm wondering if |
I tried to start work on AsyncLocalStorage, but it seems that it won't be that simple to implement (or maybe I should say there will be enough changes to have on a separate PR). We will have to do some refactoring to externalize the store for context and breadcrumbs. |
Will review over the weekend @subzero10 . Sorry for the delay. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work @subzero10, just a few concerns.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* notifyAsync + tests * simplify implementation * changelog * add test * revert to original implementation + test
@shalvah @joshuap I think this is ready. I created this issue to tackle context isolation. I already had a solution in mind about this, but now that we return both async and sync versions of the handler I will have to think about it again 😅 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work! I'll try to take it for a spin on a project soon.
@joshuap I think this is safe to merge and release, unless you have any other feedback. |
Status
READY
Description
This PR changes the result of
Honeybadger.lambdaHandler()
to be a promise based (async) handler instead of the outdated callback based handler.Discussion: #674
Issue: #677
Todos
@types/aws-lambda
)AsyncLocalStorage (or something equivalent)Separate issue: AWS Lambda - Isolated context per handler #688examples/aws-lambda/package.json
to install@honeybadger-io/js
latest release (it currently installs fromaws_lambda_async_#677
)Steps to Test or Reproduce
See
examples/aws-lambda/README.md